import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { join, resolve } from "path";
import { writeFileSync } from "fs";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";

import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // createSvgIconsPlugin({
    //   // 指定要缓存的文件夹
    //   iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
    //   // 指定symbolId格式
    //   symbolId: 'icon-[dir]-[name]',
    //   customDomId: '__svg__icons__dom__',
    // })
    AutoImport({
      imports: ["vue", "vue-router", "vuex"],
    }),
    Components({
      resolvers: [
        AntDesignVueResolver({
          resolveIcons: true,
        }),
      ],
    }),
  ],
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
      vue: "vue/dist/vue.esm-bundler.js",
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          "primary-color": "#0066FF",
          "link-color": "#0066FF",
          "border-radius-base": "2px",
        },
        javascriptEnabled: true,
      },
    },
  },
  server: {
    // host: "0.0.0.0",
    port: 9000,
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
    proxy: {
     "/api": {
      target: "http://poc03.server.zzzc.qihoo.net:9091",
      changeOrigin: true,
      // secure: false,
      // rewrite: (path) => path.replace(/^\/api/, '')
      // 不需要 rewrite，因为后端路径本身就带 /api
    },
    },
  },

  base: "/ai-app-indexManagement/",
  build: {
    outDir: "ai-app-indexManagement",
  },
});
